@extends('admin::layouts.master')
@section('title')
    编辑权益
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" >

                {{csrf_field()}}


                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">敏感词检索：</label>
                    <div class="layui-input-block" style="  padding: 9px 15px; color: red;">
                        <div class="layui-input-inline layui-show-xs-block" style="width: 300px;">
                            <input type="text" name="title" placeholder="请输入敏感词检索是否已添加" value="" autocomplete="off" class="layui-input"></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn" id="sreach" type="button">
                                <i class="layui-icon">&#xe615;</i></button>
                            <a class="layui-btn layui-btn-small" style="line-height:1.6em;float:right" onclick="location.reload()" title="刷新">
                                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
                            </a>
                        </div>
                    </div>
                </div>
<br/><br/><br/>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">设置提示：</label>
                    <div class="layui-input-block" style="  padding: 9px 15px; color: red;">
                        每两个敏感词中间使用"*"隔开（半角状态）；如添加了重复的敏感词，系统会自动去重； 例如设置了垃圾为敏感词  评论内容中出现垃圾或者垃  圾（中间含有空格）都会屏蔽，而垃【中间有其他字符】圾 将不会过滤。
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">敏感词库：</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" name="content" class="layui-textarea">{{$content}}</textarea>
                    </div>
                </div>
                <div class="">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" type="button" id="btn_edit">确认</button>
                </div>

            </form>
        </div>
    </div>

@endsection

@section('tab_js')
    <script>

        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            var is_submit = false;

            //检索
            $("body").on('click' , '#sreach' , function(){
                var title = $("input[name='title']").val();
                $.ajax({
                    url: js_url('admin-get-sensitivity-search'),
                    type: 'post',
                    data: {title:title},
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg("该敏感词暂未添加到词库中，可添加", {time: 500, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });

            });

            //提交数据
            $("body").on('click' , '#btn_edit' , function () {
                layer.confirm('确定要修改敏感词库的内容吗？', {
                    btn: ['确定'] //按钮
                }, function(){
                    var content = $("body").find('textarea[name=content]').val();
                    var id = $("input[name='id']").val();
                    $.ajax({
                        url: js_url('admin-get-sensitivity-update'),
                        type: 'post',
                        data: {content:content,id:id},
                        dataType: "json",
                        success: function (result) {
                            if (result.state === 0) {
                                layer.msg("设置成功", {time: 500, icon: 6}, function () {
                                    //关闭当前frame
                                    // xadmin.close();
                                    // 可以对父窗口进行刷新
                                    location.reload();
                                });
                            } else {
                                layer.msg(result.msg, {time: 2000, icon: 5});
                            }
                        }
                    });


                });
            });





            //监听提交
            form.on('submit(btn_edit)', function (data) {


                $.ajax({
                    url: js_url('admin-banner-store'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg("增加成功", {time: 500, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;

            });


        });
    </script>
@endsection